using System.IO;
using System.Text;
using Furion.DistributedIDGenerator;

namespace SB2.Core;

/// <summary>
/// 函数内容
/// </summary>
[SugarTable("dynamicFunctionScript")]
public class DynamicFunctionScript
{
    [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
    public long DynamicFunctionScriptID { get; set; }
    [SugarColumn(ColumnDescription = "函数信息id")]
    public long DynamicFunctionID { get; set; }
    [SugarColumn(ColumnDescription = "脚本内容")]
    public string Content { get; set; }
    [SugarColumn(ColumnDescription = "入口函数")]
    public string FunctionName { get; set; }
    [SugarColumn(ColumnDescription = "创建人")]
    public int CreateUser { get; set; }
    [SugarColumn(ColumnDescription = "创建时间")]
    public DateTime CreateDate { get; set; }

    /// <summary>
    /// 获取 代码 解码
    /// </summary>
    /// <returns></returns>
    public string GetCode()
    {
        try
        {
            string PyText = Content;
            // string PyText = Convert.ToBase64String(File.ReadAllBytes(new FileInfo("D:/c/p/2.cs").ToString()));
            // Console.WriteLine(PyText);
            var CodeString = Encoding.UTF8.GetString(Convert.FromBase64String(PyText));
            // Console.WriteLine(CodeString);
            return CodeString;
        }
        catch (Exception e)
        {
            throw new Exception($"脚本解析失败：{e.Message}");
        }

    }
}
